#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QUdpSocket>
#include <QDateTime>
#include <QTimer>
#include <QNetworkReply>
#include "mplayer.h"
#include "http.h"

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

private:
    Ui::MainWindow *ui;
    QSettings *settings;
    void init_config();

/*mplayer*/
public:
    MPlayer *mplayer;
    void startMPlayer();

/*displaytime.c*/
signals:
    void connected();
    void readyRead();
public slots:
    void displaytime_connectSucess();
    void displaytime_readingDataGrams();
    void displaytime_timer_timeout();
    void displaytime_getNetworkTimeCallback(QNetworkReply *reply);
private slots:
    void on_pushButton_baoxiu_clicked();

    void on_pushButton_jiankong_clicked();

    void on_pushButton_entranceGuard_clicked();

private:
    QUdpSocket *udpSocket;
    QString ntpIP;
    QDateTime dateTime;
    QTimer *displaytime_timer;
    void displaytime_init();
    void displaytime_setNtp();
    void displaytime_update_display(QDateTime dateTime);

/*weather.c*/
private:
    typedef struct weather_info {
        double sk_t;             //17.3
        QString sk_s;           //阴
        double sk_t_feel;        //体感温度
        QString now_summary1;   //建议
        QString ln_dt;          //农历日期
        QString pm_q;           //空气质量
        QString sk_w;           //东风2级
        int sk_h;               //适度%
    }weather_info;
    QTimer *weather_timer;
    weather_info weather_data;
    void weather_init();
    void weather_update();
    void weather_update_display(weather_info w_info);
    void weather_update_callback(QNetworkReply *reply);
    void weather_update_timeout();

/*repairs.c*/
private:
    QProcess *repairs_process;
    void repairs_init();
    void repairs_start();
    void repairs_finishedCallback(int exitCode, QProcess::ExitStatus exitStatus);
    void repairs_errorOccurred(QProcess::ProcessError error);

/*monitor.c*/
private:
    QProcess *monitor_process;
    void monitor_init();
    void monitor_start();
    void monitor_finishedCallback(int exitCode, QProcess::ExitStatus exitStatus);
    void monitor_errorOccurred(QProcess::ProcessError error);

/*guard.c*/
private:
    QProcess *guard_process;
    void guard_init();
    void guard_start();
    void guard_finishedCallback(int exitCode, QProcess::ExitStatus exitStatus);
    void guard_errorOccurred(QProcess::ProcessError error);

};
#endif // MAINWINDOW_H
